# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=musepack
pkgname=('musepack-tools' 'libmpcdec')
_revision=475
pkgver=0.1+r$_revision
pkgrel=4
epoch=1
pkgdesc='MusePack commandline utilities and decoder library'
arch=('loong64' 'x86_64')
url='https://musepack.net/'
license=('BSD' 'GPL' 'LGPL')
depends=('glibc' 'libcue' 'libreplaygain')
source=("https://files.musepack.net/source/musepack_src_r$_revision.tar.gz"
	'01_am-maintainer-mode.patch'
	'02_link-libm.patch'
	'03_mpcchap.patch'
	'04_link-order.patch'
	'05_visibility.patch'
	'1001_missing_extern_kw.patch'
	'add_subdir-objects.patch')
sha256sums=('a4b1742f997f83e1056142d556a8c20845ba764b70365ff9ccf2e3f81c427b2b'
            '76b5b7295f5e0be5de7edeb2ef481fe912cef349be5bd26f8b0870572a1ed5ee'
            'cf7ded3474ecefbe877a672539996b99dd6d62be546b74b70c4d56a7b943952d'
            'c6ef8e91b8e4450854d14e47fb4b4bde643b3f22a0d30cd0fae79d1897feb9f7'
            'b184df85c164cb6f37e077b5511bee994e767f25f641d5a44ad3877db0e7eba1'
            'db78faeb4944ab443c89a1da058693e419a8eef1ca4859550afcc6232ec407fb'
            'b736438a93fa5cc10bde753e82a0ce432db5c8c9a4a0689baa738d421166bff4'
            '88e2d7df269c8f19daccb98bd9d1a2bdc9002c7ea03ca093e2dc68b0fb04e636')

prepare() {
  cd musepack_src_r$_revision
  patch -Np1 -i ../01_am-maintainer-mode.patch
  patch -Np1 -i ../02_link-libm.patch
  patch -Np1 -i ../03_mpcchap.patch
  patch -Np1 -i ../04_link-order.patch
  patch -Np1 -i ../05_visibility.patch
  patch -Np1 -i ../1001_missing_extern_kw.patch
  patch -Np1 -i ../add_subdir-objects.patch
  mv configure.in configure.ac
  autoreconf -fi
}

build() {
  cd musepack_src_r$_revision
  ./configure --prefix=/usr --enable-mpcchap
  make
}

package_libmpcdec() {
  pkgdesc='MusePack decoding library'
  license=('BSD' 'LGPL')
  depends=('glibc')

  cd musepack_src_r$_revision
  make -C include DESTDIR="$pkgdir" install
  make -C libmpcdec DESTDIR="$pkgdir" install
  install -Dm644 libmpcdec/COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

package_musepack-tools() {
  pkgdesc='MusePack commandline tools'
  depends+=("libmpcdec>=1:0.1+r$_revision")
  options=('!emptydirs')

  cd musepack_src_r$_revision
  make DESTDIR="$pkgdir" install
  make -C libmpcdec DESTDIR="$pkgdir" uninstall
  make -C include DESTDIR="$pkgdir" uninstall
  install -Dm644 libmpcdec/COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}
